use std::error::Error;
use std::fs::File;
use std::io;
use std::io::Read;

fn main() {
    let mut result = readUserName3();
    match result {
        Ok(s) => println!("s={}", s),
        Err(error) => println!("err={:?}", error),
    }
}

fn readUserName1() -> Result<String, io::Error> {
    let f = File::open("hello.txt");
    let mut f = match f {
        Ok(file) => file,
        Err(error) => return Err(error),
    };

    let mut s = String::new();
    match f.read_to_string(&mut s) {
        Ok(_) => Ok(s),
        Err(error) => Err(error),
    }
}

fn readUserName2() -> Result<String, io::Error> {
    let mut f = File::open("hello.txt")?;
    let mut s = String::new();
    f.read_to_string(&mut s)?;
    Ok(s)
}

fn readUserName3() -> Result<String, io::Error> {
    let mut s = String::new();
    File::open("hello.txt")?.read_to_string(&mut s)?;
    Ok(s)
}

// fn aaa() -> String {
//     let mut str = String::new();
//     File::open("hello.txt").read_to_string(&mut str);
//     return str;
// }

